package J20250227_dfs;

import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:地宫取宝 https://www.lanqiao.cn/problems/216/learning/?page=1&first_category_id=1&tags=DFS&tag_relation=intersection
 * User: 王圆豪
 * Date: 2025-03-12
 * Time: 23:16
 */
public class Main5 {
    static int[][] arr;
    static boolean[][] vis;
    static int[] dx = {0,1};
    static int[] dy = {1,0};
    static int k;
    static int INF = 1000000007;
    static List<Integer> maxValue = new ArrayList<>();
    static long[][][][] memo;
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        k = scan.nextInt();
        arr = new int[n][m];
        vis = new boolean[n][m];
        memo = new long[n][m][k+1][14];
        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                arr[i][j] = scan.nextInt();
                for(int p = 0; p <= k; p++){
                    for(int q = 0; q <= 13; q++){
                        memo[i][j][p][q] = -1;
                    }
                }
            }
        }
        long ret = 0;
        maxValue.add(-1);
        vis[0][0] = true;
        ret = dfs(0,0,0) % INF;
        maxValue.remove(0);
        maxValue.add(arr[0][0]);
        ret = (ret + dfs(0,0,1))%INF;
        System.out.println(ret);
        scan.close();
    }

    public static long dfs(int x, int y, int step){
        if(x >= arr.length || y >= arr[0].length) return 0;
        if(x == arr.length-1 && y == arr[0].length-1){
            if(step == k)
                return 1;
            else return 0;
        }
        int pos = maxValue.get(maxValue.size()-1) == -1 ? 13 : maxValue.get(maxValue.size()-1);
        if(memo[x][y][step][pos] != -1) return memo[x][y][step][pos];
        long num = 0;
        for(int i = 0; i < 2; i++){
            int px = x + dx[i], py = y + dy[i];
            if(px >= 0 && px < arr.length && py >= 0 && py<arr[0].length&&!vis[px][py]){
                if(arr[px][py] > maxValue.get(maxValue.size()-1) && step < k){
                    vis[px][py] = true;
                    maxValue.add(arr[px][py]);
                    num = (num + dfs(px,py,step+1))%INF;
                    vis[px][py] = false;
                    maxValue.remove(maxValue.size()-1);
                }
                vis[px][py] = true;
                num = (num + dfs(px,py,step))%INF;
                vis[px][py] = false;
            }
        }
        memo[x][y][step][pos] = num%INF;
        return num;
    }
}
